package com.aizuda.boot.modules.business.contract.mapper;

import com.aizuda.boot.modules.business.contract.entity.ContractFieldEntity;
import com.aizuda.boot.modules.business.contract.entity.ContractModuleFieldEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author sangyirong
 * @ClassName ContractModuleFieldMapper
 * @Version 1.0
 * @Date 2025/5/29 18:12
 */
@Mapper
public interface ContractModuleFieldMapper extends BaseMapper<ContractModuleFieldEntity> {
    /**
     * 根据模块ID查询字段列表
     *
     * @param moduleId 模块ID
     * @return 字段列表
     */
    @Select("SELECT f.*, mf.field_order " +
            "FROM contract_module_field mf " +
            "JOIN contract_field f ON mf.field_id = f.id " +
            "WHERE mf.module_id = #{moduleId} " +
            "ORDER BY mf.field_order")
    List<ContractFieldEntity> findFieldsByModuleId(@Param("moduleId") Integer moduleId);

    /**
     * 根据字段ID获取模块字段关系
     *
     * @param fieldId 字段ID
     * @return 模块字段关系
     */
    @Select("SELECT * FROM contract_module_field WHERE field_id = #{fieldId} ORDER BY field_order ASC")
    ContractModuleFieldEntity selectByFieldId(Long fieldId);
    
    /**
     * 获取模块下的所有字段关系
     *
     * @param moduleId 模块ID
     * @return 字段关系列表
     */
    @Select("SELECT * FROM contract_module_field WHERE module_id = #{moduleId} ORDER BY field_order ASC")
    List<ContractModuleFieldEntity> selectByModuleId(Integer moduleId);
}